package com.lxx.wiki.service;

import com.lxx.wiki.domain.entity.Content;
import com.lxx.wiki.domain.req.ContentSaveReq;
import com.lxx.wiki.domain.resp.ContentResp;
import com.lxx.wiki.mapper.ContentMapper;
import com.lxx.wiki.utils.BeanCopyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class ContentService {



    @Autowired
    private ContentMapper contentMapper;

    public ContentResp getById(Long id) {
        Content content = contentMapper.selectByPrimaryKey(id);
        return BeanCopyUtils.copyBean(content, ContentResp.class);
    }

    public void save(ContentSaveReq contentSaveReq) {
        Content content = BeanCopyUtils.copyBean(contentSaveReq, Content.class);
        // 模拟都是文档100的内容
        content.setId(100L);
        int i = contentMapper.updateByPrimaryKeyWithBLOBs(content);
        if (i == 0){
            contentMapper.insert(content);
        }
    }
}
